//
//  FXCPhotoView.m
//  XinLangFeiBo
//
//  Created by dllo on 16/3/5.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FXCPhotoView.h"

@interface FXCPhotoView ()

@property (nonatomic, weak) UIImageView *gifView;

@end


@implementation FXCPhotoView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.contentMode = UIViewContentModeScaleAspectFill;
        self.clipsToBounds = YES;
        self.userInteractionEnabled = YES;
    }
    return self;
}

- (UIImageView *)gifView
{
    if (_gifView == nil) {
        UIImageView *gifV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"timeline_image_gif"]];
        
        _gifView = gifV;
        
        [self addSubview:gifV];
    }
    return _gifView;
}

- (void)setPhoto:(NSDictionary *)photo
{
    _photo = photo;
    NSString *url = photo[@"thumbnail_pic"];
    [self sd_setImageWithURL:photo[@"thumbnail_pic"] placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];
    if ([url hasSuffix:@".gif"]) { // gif图片
        self.gifView.hidden = NO;
    }else{
        self.gifView.hidden = YES;
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.gifView.x = self.width - self.gifView.width;
    self.gifView.y = self.height - self.gifView.height;
    
}

@end
